package com.msconfig.mvp.view.fragment;

/*
 * author: caojunhao
 * date  : 2020/6/17
 * desc  :
 */

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.geo.msconfig.R;
import com.msconfig.event.NullEvent;
import com.msconfig.mvp.view.activity.base.BaseMvpFragment;
import com.msconfig.mvp.view.activity.base.BasePresenter;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

public class SetupAboutFragment extends BaseMvpFragment implements View.OnClickListener {
    private ImageView ivCommonBack;
    private TextView tvCommonTitle;
    private TextView tvVersion;
    private Button btnCheckUpdate;
    private Context context;

    public static SetupAboutFragment newInstance() {
        Bundle args = new Bundle();
        SetupAboutFragment fragment = new SetupAboutFragment();
        fragment.setArguments(args);
        return fragment;
    }

    //当Activity与fragment建立关联时调用
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }

    @Override
    public void onClick(View v) {
        if(v==ivCommonBack){
            backTo();
        }else if(v==btnCheckUpdate){
            Toast.makeText(context,"当前版本已是最新！", Toast.LENGTH_SHORT).show();
//            Intent intent=new Intent(getActivity(), AppUpdateDialogActivity.class);
//            startActivity(intent);
        }
    }

    //目前这里只是为了实现eventbus
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void haveNull(NullEvent event) {
    }

    @Override
    protected void createPresenter(List<BasePresenter> mPresenters) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_fragment_setup_about;
    }

    @Override
    protected void initView(View view) {
        ivCommonBack=view.findViewById(R.id.iv_common_back);
        tvCommonTitle=view.findViewById(R.id.tv_common_title);
        tvVersion=view.findViewById(R.id.tv_version);
        btnCheckUpdate=view.findViewById(R.id.btn_check_update);
    }

    @Override
    protected void initListener(View view) {
        ivCommonBack.setOnClickListener(this);
        btnCheckUpdate.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        tvCommonTitle.setText(R.string.title_about);
    }
}
